package com.campus.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.campus.common.core.Pager;
import com.campus.mapper.CourseMapper;
import com.campus.mapping.CourseMapping;
import com.campus.model.TCourse;
import com.campus.model.dto.TCourseCreateDto;
import com.campus.model.vo.TCourseSelectVo;
import com.campus.service.ICourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CourseServiceImpl  extends ServiceImpl<CourseMapper, TCourse>
        implements ICourseService
{

    @Autowired
    private CourseMapper courseMapper;

    @Override
    public Integer createCourse(TCourseCreateDto courseCreateDto) {
        return courseMapper.insert(CourseMapping.INSTANCE.CreatetoCourse(courseCreateDto));
    }

    @Override
    public Page<TCourseSelectVo> getCourseList(Pager pager) {

        Page<TCourseSelectVo> page = new Page<>(pager.getPageNum(), pager.getPageSize());
        QueryWrapper qw = new QueryWrapper();
        return courseMapper.page(page,qw);
    }
}
